// pages/lstAddLawyer/lstAddLawyer.js
import request from '../../utils/config.js';
import util from '../../utils/util.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    caseDate:"",
    det: "",
    flag: "",
    caseId:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let info = JSON.parse(options.dataInfo);
    let defaultDet = info.det;
    if (info.flag == "add"){
      wx.setNavigationBarTitle({
        title: '添加诉讼法官',
      })
    } else if (info.flag == "edit"){
      wx.setNavigationBarTitle({
        title: '编辑诉讼法官',
      })
    }
    if (!defaultDet){
      defaultDet = {
        asstJudgeName:"",
        caseDate:"",
        caseNo:"",
        chiefJudgeName:"",
        clerkName:"",
        judgeName:"",
        judgeOpenDate:'',
        preservJudgeName:'',
        queryPwd:''
      }
    }
    this.setData({
      det: defaultDet,
      flag:info.flag,
      caseDate: defaultDet.caseDate,
      caseId: info.caseId
    });
  },


  //日期绑定
  caseDateChange: function(e){
    this.setData({
      caseDate: e.detail.value
    })
  },

  //提交表单
  formSubmit: function(e){
    let bodyInfo = e.detail.value;
    bodyInfo.caseDate = bodyInfo.caseDate.replace(/-/g, "");
    bodyInfo.caseId = this.data.caseId;
   
    let method = "";
    if (this.data.flag == "add"){
      method = "POST";
    }else if(this.data.flag == 'edit'){
      method = "PUT";
      bodyInfo.id = this.data.det.id
    }
    console.log("bodyInfo===", bodyInfo)
   
    wx.showLoading({ title: '加载中' })
    request.requestMisApi(method, "lawsuitJudgeInfos", bodyInfo, (res) => {
      console.log(res);
      wx.hideLoading()
      if (res.code == '00') {
        wx.showToast({ title: res.msg, icon: 'success' })
        wx.navigateBack();
      } else {
        wx.showToast({ title: res.msg, icon: 'none' })
      }
    }, (res) => {
      wx.hideLoading()
      console.log("接口错误=", res)
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  
  // }
})